package com.thinksns.sociax.t4.unit;

import android.graphics.Bitmap;
import android.os.Environment;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 保存临时temp图片类
 */

public class BitmapSaver {
    public static String savePic(Bitmap bm) {
        String fileHost = Environment.getExternalStorageDirectory() + "/korean_cache/image_cache";
        File file = new File(fileHost);
        if (!file.exists()) {
            file.mkdirs();
        }
        String filePath = fileHost + "/temp_" + System.currentTimeMillis() + ".jpg";
        boolean isOk = false;
        File image = new File(filePath);
        if (image.exists()) {
            image.delete();
        }
        try {
            FileOutputStream out = new FileOutputStream(image);
            isOk = bm.compress(Bitmap.CompressFormat.PNG, 80, out);
            out.flush();
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (isOk)
            return filePath;
        return null;
    }
}
